using System;
using System.Diagnostics.CodeAnalysis;

namespace Lombiq.HelpfulLibraries.Common.Utilities;

/// <summary>
/// <see cref="Random"/> 的包装器，强调它不是用于任何安全关键目的。通过使用此类，用户承认这一点，这意味着不再需要手动禁用 <see
/// href="https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca5394#when-to-suppress-warnings">
/// CA5394</see> 警告。
/// </summary>
[SuppressMessage(
    "Microsoft.Security",
    "CA5394",
    Justification = "The name makes it explicit that it's not a security concern.")]
[SuppressMessage(
    "Security",
    "SCS0005:Weak random number generator.",
    Justification = "The name makes it explicit that it's not a security concern.")]
public class NonSecurityRandomizer
{
    private readonly Random _random;

    public NonSecurityRandomizer(int seed) => _random = new Random(seed);

    public NonSecurityRandomizer() => _random = new Random();

    /// <summary>
    /// 返回至少为 0 且小于 <paramref name="below"/> 的随机 <see cref="int"/>。
    /// </summary>
    public int GetFromRange(int below) => _random.Next(below);

    /// <summary>
    /// 返回 0 到 <see cref="int.MaxValue"/>（包含）之间的随机 <see cref="int"/>。
    /// </summary>
    public int Get() => _random.Next();

    /// <summary>
    /// 返回 0 到 <see cref="double.MaxValue"/>（包含）之间的随机 <see cref="double"/>。
    /// </summary>
    public double GetDouble() => _random.NextDouble();
}
